//
//  YCScan1ViewController.m
//  DemoZBar
//
//  Created by 唐可雄 on 16/8/24.
//  Copyright © 2016年 swustyc. All rights reserved.
//

#import "YCScan1ViewController.h"

#import "ZBarSDK.h"

@interface YCScan1ViewController ()<ZBarReaderDelegate>

@end

@implementation YCScan1ViewController

#pragma mark - Life Cycle

#pragma mark - IBAction

- (IBAction)scanBtnDidClick:(id)sender {
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    
    ZBarImageScanner *scanner = reader.scanner;
    
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    
    [self presentViewController:reader
                       animated:YES
                     completion:nil];
}

#pragma mark - ZBarReaderDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // 获取第一个
        break;
    
    self.resultTxtView.text = symbol.data;
    
    self.imgView.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];
    
    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [picker dismissViewControllerAnimated:YES completion:nil];
}

@end
